package com.example.newYear.mesageObserver;

import java.util.ArrayList;
import java.util.List;

//具体的消息服务器实现类，作为被观察的主题
public class MessageServer implements MessageSubject {

    private List<MessageObserver> observerList = new ArrayList<>();

    @Override
    public void notifyObserver(Message message) {
        for (MessageObserver messageObserver : observerList) {
            messageObserver.update(message);
        }
    }

    @Override
    public void registerObserver(MessageObserver observer) {
        observerList.add(observer);
    }

    @Override
    public void removeObserver(MessageObserver observer) {
        observerList.remove(observer);
    }
}
